//
//  UIView+Method.m
//  SegmentDemo
//
//  Created by 塔兮 on 2022/4/11.
//

#import "UIView+Method.h"

@implementation UIView (Method)

- (UIViewController*)viewController {
    for (UIView* next = [self superview]; next; next = next.superview) {
        UIResponder* nextResponder = [next nextResponder];
        if ([nextResponder isKindOfClass:[UIViewController class]]) {
            return (UIViewController*)nextResponder;
        }
    }
    return nil;
}

- (void)removeAllSubViews {
    for (UIView *subview in self.subviews){
        [subview removeFromSuperview];
    }
}

- (void)setCornerRadius:(CGFloat)radius {
    CALayer *layer = self.layer;
    layer.cornerRadius = radius;
    layer.masksToBounds = YES;
    [self setNeedsDisplay];
}

- (void)setBorderWidth:(CGFloat)width color:(UIColor *)color radius:(CGFloat)radius {
    CALayer *layer = self.layer;
    layer.borderColor = color.CGColor;
    layer.borderWidth = width;
    layer.cornerRadius = radius;
    layer.masksToBounds = YES;
    [self setNeedsDisplay];
}

@end
